<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>斐波那契数列</title>
		<style type="text/css">
			p{
				text-align: center;
			}
		</style>
	</head>
	<body>
		<script>
			var w = prompt("请输入斐波那契数列的位数");
			document.write(1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + 1 + "<br/>");
			document.write(1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + 2 + "<br/>");
			for(var i = 3; i <= w; i++) {
				function xj(n) {
					if(n == 1 || n == 2) {
						return 1;
					} else {
						return xj(n - 1) + xj(n - 2);
					}
				}
				document.write(xj(i - 2) + "+" + xj(i - 1) + "=" + xj(i) + "&nbsp;&nbsp;&nbsp;&nbsp;" + i + "<br/>");
			}
			alert("斐波那契数列第" + w + "位是" + xj(w));
			document.write("<p style='color:red;'>由以上数列得出斐波那契数列第" + w + "位是" + xj(w) + "。</p>");
		</script>
	</body>
</html>
